Home

Introduction to Scripts

Introduction

There are various types of places where you will write your code. As mentioned already, you can create delimiting sections where you would write your code. Some other types of code will require that you create your code in the head section. To write ASP.NET code in the head section, you must create a script.

Creating a Script

To get a script in the head section, start a <script> tag and close it with an end </script> tag. Here is an example:

<%@ Page Language="VB" %>

<!DOCTYPE html>

<html>
<head>

<script>

</script>

<title>Exercise</title>

</head>
<body>

</body>
</html>

The <script> tag uses various attributes. To start, you must specify that the script will run on the server. To do this, add the runat="server" attribute to it. This can be done as follows:

<%@ Page Language="VB" %>

<!DOCTYPE html>

<html>
<head>

<script runat="server">

</script>

<title>Exercise</title>

</head>
<body>

</body>
</html>

After doing this, you can create your code between the starting <script> and the end </script> tags.

When writing your code, because you have determined that the page will use the Visual Basic language, you can simply write your code as you see fit. To let you specify the language of your code, the <script> tag is equipped with an attribute named Language. To specify the language, assign it to the Language attribute. Here is an example:

<%@ Page Language="VB" %>

<!DOCTYPE html>


<html>
<head>

<script language="VB" runat="server">

</script>

<title>Exercise</title>

</head>
<body>

</body>
</html>

To specify a language, assign:

  • text/VB to the type attribute if you will use the VB language. Here is an example:
    <%@ Page Language="VB" %>
    
    <!DOCTYPE html>
    
    <html>
    <head>
    
    <script language="VB" type="text/VB" runat="server">
    
    </script>
    
    <title>Exercise</title>
    
    </head>
    <body>
    
    </body>
    </html>
  • text/C# to the type attribute if you will use the C# language
  • text/vbsscript to the type attribute if you use the VBScript language
  • text/javascript to the type attribute if you will use the JavaScript language
  • text/jscript to the type attribute if you will use the JScript language
  • text/ecmascript to the type attribute if you will use ECMAScript

Remember that only the runat attribute is required. The others are optional. After specifying the values of the desired attributes, you can create your code.